package com.h2.ref.server.util.sec;

import java.security.SecureRandom;

public class TokenGenerator {
   
   private static final SecureRandom RANDOM = new SecureRandom();
   
   public static final char[] MIXED_CASE_ALPHA_NUMERIC = { '1', '2', '3', '4',
      '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
      'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
      'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm',
      'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
   
   public static String generateRandom(int size) {
      return generateRandom(MIXED_CASE_ALPHA_NUMERIC, size);
   }
   
   public static String generateRandom(char[] array, int size) {
      int charArraySize = array.length;
      StringBuilder builder = new StringBuilder();
      for (int i = 0; i < size; i++) {
         builder.append(array[RANDOM.nextInt(charArraySize)]);
      }
      return builder.toString();
   }

}
